<template>
  <a-card :bordered="false" class="card-area">

   <a-row>
     <a-col :span='12'>
       <bar title="会员年度发展趋势" :dataSource="dataSourceBar" :height="height" yaxisText='人数'/>
     </a-col>

     <a-col :span='12'>
       <pie :height="height" :dataSource="dataSourcePie"/>
     </a-col>
   </a-row>

    <!-- 操作按钮区域 -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource">
      </a-table>
    </div>
  </a-card>
</template>

<script>
  import JDate from '@comp/jeecg/JDate'
  import Bar from '@/components/chart/Bar'
  import Pie from '@/components/chart/Pie'
  import LineChartMultid from '@/components/chart/LineChartMultid'
  import { getAction } from '@api/manage'


  export default {
    name: "DepartList",
    components: {
      JDate,
      Pie,
      Bar,
      LineChartMultid
    },
    data () {
      return {
        description: '机构服务工单处理页面',
        // 查询条件
        height: 400,
        dataSource:[],
        dataSourcePie:[],
        dataSourceBar:[],
        // 表头
        columns: [
          {
            title: '会员等级',
            align:"center",
            dataIndex: 'gradeName'
          },{
            title: '人数',
            align:"center",
            dataIndex: 'count'
          },
        ],
        url: {
          list: "/ch/report/member/list",
        },
      }
    },
    computed: {
    },
    created() {
      const that=this;
      getAction('/ch/report/member/list').then((res) => {
        if(res.success){
          that.dataSource=res.result;
          res.result.forEach((item) => {
             that.dataSourcePie.push(      { item: item.gradeName, count: item.count },)
          })
        }
      })
      getAction('/ch/report/member/sumMonthCount').then((res) => {
        if(res.success){
          setTimeout(() => {
            that.dataSourceBar= that.loadData1('x', 'y', res.result)
          }, 100)
        }
      })
    },
    methods: {
      loadData1(x, y,dbList, after = '月') {
        let data = []
        for (let i = 0; i < 12; i += 1) {
          const  db=dbList[i];
          data.push({
            [x]: `${db.months}${after}`,
            [y]: db.total
          })
        }
        return data
      },

      loadData(x, y, max, min, before = '', after = '月') {
        let data = []
        for (let i = 0; i < 12; i += 1) {
          data.push({
            [x]: `${before}${i + 1}${after}`,
            [y]: Math.floor(Math.random() * max) + min
          })
        }
        return data
      },

      handleAdd: function () {
        this.$router.push({path:'/ihis/org/schedulingEdit'})
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>